package com.ruoyi.common.core.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * OneManage全局常量类
 * 
 * @author wangh
 * 
 */
public class Global
{
	/**
	 * 当前对象实例
	 */
	private static Global global = new Global();
	
	/**
	 * 保存全局属性值
	 */
	private static Map<String, String> map = new HashMap<String, String>();
	
	/**
	 * 属性文件加载对象
	 */
//	private static PropertiesLoader loader = new PropertiesLoader("classpath:dbconfig.properties");
	
	/**
	 * 检查点层级：一级
	 */
	public final static String CHECK_LEVEL_ONE = "1";
	
	/**
	 * 检查点层级：二级
	 */
	public final static String CHECK_LEVEL_TWO = "2";
	
	/**
	 * 检查点层级：三级
	 */
	public final static String CHECK_LEVEL_THREE = "3";
	
	/**
	 * 检查点层级：四级
	 */
	public final static String CHECK_LEVEL_FOUR = "4";

	/**
	 * 是
	 */
	public static final String YES = "1";

	/**
	 * 否
	 */
	public static final String NO = "0";
	
	// 数据库备份文件命令
	public static final String WIN_COMMAND = "cmd /c";
	public static final String LINUX_COMMAND = "/bin/sh -c";
	// 数据库备份文件存储路径
	public static final String WIN_DIR = "C:";
	public static final String LINUX_DIR = "/opt/physical";
	
	//批量上传数据文件夹
	public static final String BATCHUP_DIR = "batchUp";
	
	//批量上传数据文件夹
	public static final String BATCHUPBACKUP_DIR = "batchUpBackUp";
	
	//登录时，用户名和密码加密密钥
	public static final String USER_AES_SECRETKEY = "XpxCPhbFO+uJwAfxhGOo9g==";
	
	//系统用户密码和个人信息realname,idcard,address,workunit,phone加密存储到数据库中时的加密密钥
	public static final String COLS_AES_SECRETKEY = "Kwp4l0oewQMOfj45FUGjqg==";
	
	//系统用于AES密钥的加密
	public static final CryptoUtils.AsymmetricKeyPair RSA_SECRETKEY = new CryptoUtils.AsymmetricKeyPair("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCVc6GBi0tVk+vONRdoIZoEzZw5MFjGwyrOyfHERY2GeHWgz+o2WFUIjdTP2lUbnhuqzQiFBXrK8USXW3/mmDBsMVgjIngSrCD1BG9nzXONMOGdI9kuDlcflHkFsf+csLwgqQiu1rVj/c3LBfz9hczfi1+ZYsJnk2+mp1pJIKhq/QIDAQAB","MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJVzoYGLS1WT6841F2ghmgTNnDkwWMbDKs7J8cRFjYZ4daDP6jZYVQiN1M/aVRueG6rNCIUFesrxRJdbf+aYMGwxWCMieBKsIPUEb2fNc40w4Z0j2S4OVx+UeQWx/5ywvCCpCK7WtWP9zcsF/P2FzN+LX5liwmeTb6anWkkgqGr9AgMBAAECgYAVEQWVEyN9XqqAmK9B+GqTfsAkt5HsAprIJ2My/XLjn5tFHcmv+2eRGx0CZ45TpEfWHayzw3/5l2TJyRYQVSeOASbyUtz9c2t3lxZpfHb9mrgLA1y5nkd5QWJOFsX+2N4PkABPnPipQ1rKPlGWbdT662L1pX9gZCIdmtqZMshZgQJBANwnW/kzBXDbl81MkaafkvajIad081mvBl/AN3+NeKjp9Be/xZriV4qyb0/CCs+rHVbqaXJj5i5/+rBGyFAFDzECQQCtyTTZXlDkV4PUe42iPg4+TLvLGYwKCJpt4B16U9Wxjqgarrv5CCM6aEv/D6RNuxgLnTrKCxi2nbU/114U7p2NAkEAjUhNA+20Tir+jmfXCQFbRSCHlnm9Og7SnlwywY6+olgRp7QQUkdzOrUsLhku6vq7R24D4b8ulyTWco3aO1Aj4QJBAI0Zz8IpdO5hLBVql83CKthkfxlhTbWb1J8fl2+J//hhRpYbh12kQM4cfo/CSHogTV6os2H2boNfOxlxqN6/+sUCQHHPKqkcMsWG55vxOIWwGe2+fXAez84ZneZ0aGGZ3I2azpALI0IVBq2XODNZSocOWxGAB6Xt+1ENaHBfn/siOLA=");
	
	/**
	 * 按照总项目数做综合评价
	 */
	public static final boolean PRONUM = true;
	
	/**
	 * 2019年国民体质测试综合评价的指标名称“国民体质综合评价”
	 */
	public static final String TOTALITEMNAME = "国民体质综合评价";
	
	/**
	 * 5.0新软件国民体质测试综合评价的指标code是“100”
	 */
	public static final String TOTALITEMCODE = "100";
	
	/**
	 * 2019年国民体质测试的综合评价等级code是4
	 */
	public static final Integer BUHEGECODE = 4;
	
	/**
	 * 国民体质测试的综合评价不合格等级是“不合格”
	 */
	public static final String BUHEGEDENGJI = "不合格";
	
	/**
	 * 全国数据表以t为前缀
	 */
	public static final String DATATABLEPRE = "t";
	
	/**
	 * 全国数据表初始标识符是a
	 */
	public static final String DATATABLESTARTTAG = "a";
	
	/**
	 * 全国数据表初始标识符a对应的年份是2020
	 */
	public static final String DATASTARTYEAR = "2020";
	
	/**
	 * 全国数据表初始标识符a对应的年份是2020
	 */
	public static final String CALPCIDLABLE = "PCID";
	
	/**
	 * 全国数据表初始标识符a对应的年份是2020
	 */
	public static final String CALGMTZIDLABLE = "GMTZID";
	
	/**
	 * 登记信息数据表名dengjixinxi
	 */
	public static final String HUIYUANXINXINAME = "testmember";
	
	/**
	 * 功率车数据表名gonglvche
	 */
	public static final String GONGLVCHENAME = "testpower";
	
	/**
	 * 功率车心率数据表名gonglvche
	 */
	public static final String GONGLVCHEHEARTRATENAME = "testpowerheartrate";
	
	/**
	 * 国民体质测试数据表名guomintizhiceshi
	 */
	public static final String GUOMINTIZHICESHINAME = "testcorporeity";
	
	/**
	 * 血压计数据表名xueyaji
	 */
	public static final String XUEYAJINAME = "testturgoscope";
	
	/**
	 * 体脂率数据表名tichengfen
	 */
	public static final String TICHENGFENNAME = "testbodyfat";
	
	/**
	 * 完整测试数据表名
	 */
	public static final String TESTWHOLEDATANAME = "testwholedata";
	
	/**
	 * 完整测试数据表名
	 */
	public static final String RETESTWHOLEDATANAME = "testwholedataretest";
	
	/**
	 * 测试点机构代码长度14
	 */
	public static final int ORGCODEMAXLEN = 14;


	/**
	 * 获取文件上传/下载的基本路径
	 * 兼容Linux和Windows系统
	 *
	 * @return 文件存储基本路径
	 */
	public static String getProfile() {
		// 判断操作系统类型
		String os = System.getProperty("os.name").toLowerCase();

		if (os.contains("win")) {
			// Windows系统路径
			return "C:" + File.separator + "ruoyi" + File.separator + "uploadPath";
		} else {
			// Linux/Unix/Mac系统路径
			return File.separator + "opt" + File.separator + "ruoyi" + File.separator + "uploadPath";
		}
	}

	/**
	 * 获取下载路径
	 *
	 * @return 下载路径
	 */
	public static String getDownloadPath() {
		return getProfile() + File.separator + "download";
	}

	/**
	 * 获取上传路径
	 *
	 * @return 上传路径
	 */
	public static String getUploadPath() {
		return getProfile() + File.separator + "upload";
	}

	/**
	 * 确保目录存在，如果不存在则创建
	 *
	 * @param path 目录路径
	 * @return 是否成功创建或目录已存在
	 */
	public static boolean ensureDirectoryExists(String path) {
		File directory = new File(path);
		if (!directory.exists()) {
			return directory.mkdirs();
		}
		return true;
	}

	/**
	 * 初始化目录结构
	 */
	public static void initDirectories() {
		ensureDirectoryExists(getProfile());
		ensureDirectoryExists(getDownloadPath());
		ensureDirectoryExists(getUploadPath());
	}

	// 其他方法...

	// 静态初始化块，确保目录结构存在
	static {
		initDirectories();
	}
	
	//参与评价的各年龄段，性别，需要的指标信息List
	public static final List<Map<String, String>> ZHIBIAOLIST = new ArrayList<Map<String, String>>();
	
	static{
		Map<String, String> map1 = new HashMap<String, String>();
		Map<String, String> map2 = new HashMap<String, String>();
		Map<String, String> map3 = new HashMap<String, String>();
		Map<String, String> map4 = new HashMap<String, String>();
		Map<String, String> map5 = new HashMap<String, String>();
		map1.put("items", "'身高坐高_身高(幼儿)','身高标准体重(幼儿)','15米障碍跑(幼儿)','立定跳远(幼儿)','握力(幼儿)','双脚连续跳(幼儿)','坐位体前屈(幼儿)','平衡木(幼儿)'");
		map1.put("ageMin", "3");
		map1.put("ageMax", "6");
		map1.put("sex", "");
		ZHIBIAOLIST.add(map1);
		map2.put("items", "'身高标准体重','肺活量','心肺耐力','握力','俯卧撑','纵跳','坐位体前屈','选择反应时','闭眼单脚站立'");
		map2.put("ageMin", "20");
		map2.put("ageMax", "39");
		map2.put("sex", "男");
		ZHIBIAOLIST.add(map2);
		map3.put("items", "'身高标准体重','肺活量','心肺耐力','握力','1分钟仰卧起坐','纵跳','坐位体前屈','选择反应时','闭眼单脚站立'");
		map3.put("ageMin", "20");
		map3.put("ageMax", "39");
		map3.put("sex", "女");
		ZHIBIAOLIST.add(map3);
		map4.put("items", "'身高标准体重','肺活量','心肺耐力','握力','坐位体前屈','选择反应时','闭眼单脚站立'");
		map4.put("ageMin", "40");
		map4.put("ageMax", "59");
		map4.put("sex", "");
		ZHIBIAOLIST.add(map4);
		map5.put("items", "'身高标准体重','肺活量','握力','坐位体前屈','选择反应时','闭眼单脚站立'");
		map5.put("ageMin", "60");
		map5.put("ageMax", "79");
		map5.put("sex", "");
		ZHIBIAOLIST.add(map5);
	}
	

	/**
	 * 获取配置
	 * @see ${fns:getConfig('adminPath')}
	 */
/*	public static String getConfig(String key) {
		String value = map.get(key);
		if (value == null){
			value = loader.getProperty(key);
			map.put(key, value != null ? value : StringUtils.EMPTY);
		}
		return value;
	}
	*/
	/**
	 * 根据当前年份计算出当年数据表标识符
	 * @return 当年数据表的标识符
	 */
	public static String getCurTag(String curYear){
		String curTag = "";
		//当前年份和初始年份2020年的差
		int yearNum = Integer.parseInt(curYear) - Integer.parseInt(DATASTARTYEAR);
		if(yearNum < 0){
			return curTag;
		}
		//数据表初始标识符a的acsii是97
		int dataTableStartTag1 = DATATABLESTARTTAG.toCharArray()[0];
		//当前年份的数据表标识符
		curTag = curTag + ((char) (dataTableStartTag1+yearNum));
		return curTag;
	}
	
}
